#include "Offset.h"


Offset::Offset(vm *_env, Expr *_expr, Token *_tok)
    : env(_env), rExpr(_expr), lExpr(NULL), Assignable(_tok)
{
}

Offset::Offset(vm *_env, Expr *_exprR, Expr *_exprL, Token *_tok)
    : env(_env), rExpr(_exprR), lExpr(_exprL),Assignable(_tok)
{
}


Offset::~Offset(void)
{
    delete rExpr;
    delete lExpr;
}

int Offset::DoEvalInt()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetElement(Name(), row, line);
}

std::string Offset::Name()
{
    return token->GetStrProp();
}

float Offset::DoEvalFlt()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetFltElement(Name(), row, line);
}

void Offset::SetValue( int val )
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetElement(Name(), row, line, val);
}

void Offset::SetValue( float val )
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetFltElement(Name(), row, line, val);
}

void Offset::SetMaxValue(int val)
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetElementForInfo(Name(), row, line, val);
}

void Offset::SetMaxValue(float val)
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetFltElementForInfo(Name(), row, line, val);
}

int Offset::MaxValue()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetElementMaxValue(Name(), row, line);
}

float Offset::MaxFltValue()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetFltElementMaxValue(Name(), row, line);
}

void Offset::SetStep( int step )
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetElementForStep(Name(), row, line, step);
}

void Offset::SetStep(float step)
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    env->SetFltElementForStep(Name(), row, line, step);
}

int Offset::Step()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetElementForStep(Name(), row, line);
}

float Offset::FltStep()
{
    int row = rExpr->EvalInt();
    int line = (lExpr == NULL) ? 0 : lExpr->EvalInt();
    return env->GetFltElementForStep(Name(), row, line);
}

